package com.glepoch.springbootsecuritymybatis.compoment.easyexcel.listen;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.glepoch.springbootsecuritymybatis.utils.CopyBeanUtils;

import java.util.List;

/**
 * @description:
 * @author: ygl
 * @time: 2021/1/8 19:44
 */
public class ExcelListener<T> extends AnalysisEventListener<Object> {
    private List<T> datas;
    private Class<T> clazz;

    private ExcelListener() {
    }
    public ExcelListener(List<T> datas,Class<T> clazz) {
        this.datas = datas;
        this.clazz=clazz;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }

    public Class<T> getClazz() {
        return clazz;
    }

    public void setClazz(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public void invoke(Object studentEntity, AnalysisContext analysisContext) {
        datas.add(CopyBeanUtils.beanToBean(studentEntity,clazz));
        System.out.println(studentEntity);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
